package com.example.springbootweb_comprehensiveexample.mapper;

import com.example.springbootweb_comprehensiveexample.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    //查询总记录数(原始)
    /*@Select("select count(*) from emp")
    public Long count();

    //分页查询获取员工表信息
    @Select("select * from emp limit #{start}, #{pageSize}")
    public List<Emp> page(@Param("start") Integer start, @Param("pageSize") Integer pageSize);*/

    //员工信息查询（由pagehelper整合）  复杂的多参数 用xml映射文件
    //@Select("select * from emp")
    public List<Emp> list(@Param("name") String name, @Param("gender") Short gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    //批量删除员工
    public void delete(@Param("ids") List<Integer> ids);

    //添加员工
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            " values(#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    void insert(Emp emp);

    //根据id查询员工
    @Select("select * from emp where id = #{id}")
    Emp selectById(Integer id);

    void update(Emp emp);

    //登录
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);

    //退出登录
    @Select("select * from emp where username = #{username} and password = #{password}")
    void logout(@Param("username") String username, @Param("password") String password);

    //删除部门中的员工
    @Delete("delete  from Emp where dept_id = #{deptId} ")
    void deleteEmpByDeptId(Integer deptId);

}
